<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
require_once("../change_page.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" charset= "utf-8 "/>
        <title>乐知家园</title>
        <script language="javascript">
            function deleteproduct(id,name,page){
                var str = "\u786e定删除 " + name + "\uff1f";
                if(confirm(str)){
                    location.href = "deleteGold.php?ids=" + id + "&page=" + page;
                }
            }
            function approve(id,direct,name,page){
                var str = "";
                if(direct=="up"){
                    str = name + " \u786e定发布？";
                }else if(direct=="down"){
                    str = name + " \u786e定下线？";
                }
                if(confirm(str)){
                    location.href = "approveAnimation.php?ids=" + id + "&direct=" + direct + "&page=" + page;
                }
            }
            function search_key(){
                var key = document.getElementById("keyword").value;
                if(key==null||key==''){
                    alert("\u8bf7输入关键字");
                } else {
                    var page = document.getElementById("current_page").value;
                    location.href = "goldList.php?keyword=" + key + "&page=" + page+"&menu=gold";
                }
            }

            function click_all(e){
                var checkboxes = document.getElementsByName("product_checkbox");
                for(var i=0;i<checkboxes.length;i++){
                    if(e.checked){
                        checkboxes[i].checked = true;
                    }else{
                        checkboxes[i].checked = false;
                    }
                }
            }
            function delete_product_multi(){
                var str = "\u786e定删除选中的应用？";
                if(confirm(str)){
                    var ids = "";
                    var checkboxes = document.getElementsByName("product_checkbox");
                    for(var i=0;i<checkboxes.length;i++){
                        if(checkboxes[i].checked){
                            ids = ids + checkboxes[i].value + ",";
                        }
                    }
                    location.href = "deleteAnimation.php?ids=" + ids;
                }
            }
            function approve_multi(direct){
                var str = "";
                if(direct=="up"){
                    str = "\u786e定发布选中的应用？";
                }else if(direct=="down"){
                    str = " \u786e定下线选中的应用？";
                }
                if(confirm(str)){
                    var ids = "";
                    var checkboxes = document.getElementsByName("product_checkbox");
                    for(var i=0;i<checkboxes.length;i++){
                        if(checkboxes[i].checked){
                            ids = ids + checkboxes[i].value + ",";
                        }
                    }
                    location.href = "approveAnimation.php?ids=" + ids + "&direct=" + direct;
                }
            }

            function top(id,direct,name,page){
                var str = "";
                if(direct=="up"){
                    str = name + " \u786e定推荐？";
                }else if(direct=="down"){
                    str = name + " \u786e定取消？";
                }
                if(confirm(str)){
                    location.href = "topAnimation.php?ids=" + id + "&direct=" + direct + "&page=" + page;
                }
            }
        </script>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #000000;
            }

            .STYLE1 {color: #FFFFFF}
            -->
        </style></head>
    <body>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
            <tr align="align">
                <td bgcolor="#FFFFFF"><a href="goldEdit.php?menu=gold">新建</a>&nbsp;<a href="#" onclick="delete_product_multi()">删除</a>&nbsp;<a href="#" onclick="approve_multi('up')">发布</a>&nbsp;<a href="#" onclick="approve_multi('down')">下线</a>&nbsp;<!--<a href="#" onclick="approve_multi_en('up')">国外发布</a>&nbsp;<a href="#" onclick="approve_multi_en('down')">国外下线</a>--></td>
                <td bgcolor="#FFFFFF" align="left">&nbsp;</td>
                <td>&nbsp;</td>
                <td bgcolor="#FFFFFF" align="right"><?php
                $page_size = 100;
                if (isset($_GET['page'])) {
                    $page = $_GET['page'];
                } else {
                    $page = 0;
                }
                $sql = "SELECT COUNT(*) AS total FROM t_hibaby_gold";
                $db = new DBC();
                $total_num = $db->fetchData($sql);
                if ($total_num != null) {
                    $total_num_product = $total_num[0]['total'];
                }
                $page_count = getPageSize($total_num_product, $page_size);
                echo getPage("goldList.php?menu=gold", $page_count, $page);
                ?></td>
            </tr>
        </table>
        <br/>
        <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#9999FF">
            <tr align="center">
                <td bgcolor="#666666"><input name="all" type="checkbox" onclick="click_all(this)" /><input name="current_page" id="current_page" type="hidden" value="<?php echo $page; ?>" /></td>
                <td bgcolor="#666666"><span class="STYLE1">序号</span></td>
                <td bgcolor="#666666"><span class="STYLE1">编号</span></td>
                <td bgcolor="#666666"><span class="STYLE1">名称</span></td>
                <td bgcolor="#666666"><span class="STYLE1">价格</span></td>
                <td bgcolor="#666666"><span class="STYLE1">有效天数</span></td>
                <td bgcolor="#666666"><span class="STYLE1">版本</span></td>
                <td bgcolor="#666666"><span class="STYLE1">描述</span></td>
                <td bgcolor="#666666"><span class="STYLE1">创建时间</span></td>
                <td bgcolor="#666666"><span class="STYLE1">操作</span></td>
                <td bgcolor="#666666"><span class="STYLE1">发布<!--（国内、国外）--></span></td>
                <td bgcolor="#666666"><span class="STYLE1">推荐</span></td>
            </tr>
            <?php
            $begin = $page * $page_size;
            
            $sql = "SELECT * FROM t_hibaby_gold ORDER BY createTime LIMIT " . $begin . "," . $page_size;
            
            $num = $begin;
            $data = $db->fetchData($sql);
            foreach ($data as $product) {                
                ?>
                <tr>
                    <td bgcolor="#FFFFFF" align="center"><input type="checkbox" name="product_checkbox" value="<?php echo $product['productid']; ?>"/></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo++$num; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['code']; ?></td>
                    <td bgcolor="#FFFFFF">&nbsp;<?php echo $product['name']; ?></td>
                    <td align="right" bgcolor="#FFFFFF"><font color="green"><b><?php echo $product['price']; ?></b></font> 金币</td>
                    <td align="right" bgcolor="#FFFFFF"><font color="green"><b><?php echo $product['validateDays']; ?></b></font> 天</td>
                    <td align="right" bgcolor="#FFFFFF"><font color="green"><b><?php echo $product['version']; ?></b></font> </td>
                    <td align="right" bgcolor="#FFFFFF"><font color="green"><b><?php echo $product['description']; ?></b></font> </td>
                    <td align="center" bgcolor="#FFFFFF"><?php echo $product['createTime']; ?><!--&nbsp;< ? php echo $status_en; ?>--></td>
                    <td align="center" bgcolor="#FFFFFF"><a href="goldEdit.php?menu=gold&code=<?php echo $product['code']; ?>">编辑</a>&nbsp;<a href="#" onclick="deleteproduct('<?php echo $product['code']; ?>','<?php echo $product['code'] . "-" . $product['name']; ?>','<?php echo $page; ?>')">删除</a></td>
                    <td align="center" bgcolor="#FFFFFF"></td>
                    <td align="center" bgcolor="#FFFFFF"></td>
                </tr>
            <?php } ?>
        </table>
    </body>
</html>
<?php
include_once '../footer.php';
//} else {
//    header("login.php");
//}
?>